
#ifndef RtThreadMacEventPatch_H__
#define RtThreadMacEventPatch_H__
#pragma once

#ifndef MachOSupport
#include <CarbonEvents.h>
#endif	//MachOSupport

#include "RtThread.h"
#include "RtReactorBase.h"

class CRtTimerQueueBase;
class CRtTimeValue;

// WebEx custom event types
const UInt32 kEventClassWebExTpEvent = 'WeTp';

// WebEx custom event kinds
const UInt32 kEventKindWebExTpEvent = 'EKTP';

// WebEx custom event parameter names
const UInt32 kParamNameTpSocketReference = 'nTpS';
const UInt32 kParamTypeTpSocketReference = 'tTpS';

class CRtThreadMacEventPatch
	: public CRtThread
	, public CRtEventQueueUsingMutex
{
public:
	CRtThreadMacEventPatch();
	~CRtThreadMacEventPatch();
	
	// interface CRtThread
	virtual RtResult Stop(CRtTimeValue* aTimeout = NULL);
	virtual void OnThreadInit();
	virtual void OnThreadRun();
	virtual IRtEventQueue* GetEventQueue();
	virtual IRtTimerQueue* GetTimerQueue();
	
	// interface IRtEventQueue
	virtual RtResult PostEvent(IRtEvent *aEvent, EPriority aPri = EPRIORITY_NORMAL);
	
	RtResult ProcessEventQueue();
	RtResult ProcessTimer();
	
private:
	void TpMacSocketMessage();

private:
	CRtTimerQueueBase *m_pTimerQueue;
	BOOL m_bStopped;
	
	EventLoopTimerRef   m_nTimer ;
	EventLoopTimerUPP	m_theTimerUPP;
	EventTime			m_TimerFrequency ;
	
	EventHandlerUPP		m_handlerUPP;
	EventHandlerRef		m_TpEventHandlerRef;		// cache this and dispose of at app quit	
};

#endif //RtThreadMacEventPatch_H__
